package com.mk.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ配置类-Topic
 *
 * @author: LC
 * @date 2022/3/8 5:24 下午
 * @ClassName: RabbitMQTopicConfig
 */
@Configuration
public class RabbitMQTopicConfig {
    /**
     * @Author hhwu
     * @Description //TODO 秒杀时真正使用的消息队列配置
     * @Date 10:18 2022/6/13
     **/

    private static final String QUEUE = "seckillQueue";
    private static final String EXCHANGE = "seckillExchange";

    @Bean
    public Queue queue() {// 定义一个队列
        return new Queue(QUEUE);
    }

    @Bean
    public TopicExchange topicExchange() {// 定义一个交换机
        return new TopicExchange(EXCHANGE);
    }

    @Bean
    public Binding binding() {// 绑定队列和交换机
        return BindingBuilder.bind(queue()).to(topicExchange()).with("seckill.#");// 通过路由key，指定队列匹配规则
    }










    /**
     * @Author hhwu
     * @Description //TODO 学习rabbitmq,topic模式，是direct模式的模糊匹配方式，将发来的消息的精确路由key模糊匹配的到指定规则的队列中
     * @Date 15:00 2022/6/11
     **/
//    private static final String QUEUE01 = "queue_topic01";
//    private static final String QUEUE02 = "queue_topic02";
//    private static final String EXCHANGE = "topicExchange";
//    private static final String ROUTINGKEY01 = "#.queue.#";// 匹配规则
//    private static final String ROUTINGKEY02 = "*.queue.#";
//
//    @Bean
//    public Queue queue01() {
//        return new Queue(QUEUE01);
//    }
//
//    @Bean
//    public Queue queue02() {
//        return new Queue(QUEUE02);
//    }
//
//    @Bean
//    public TopicExchange topicExchange() {
//        return new TopicExchange(EXCHANGE);
//    }
//
//
//    @Bean
//    public Binding binding01() {
//        return BindingBuilder.bind(queue01()).to(topicExchange()).with(ROUTINGKEY01);
//    }
//
//    @Bean
//    public Binding binding02() {
//        return BindingBuilder.bind(queue02()).to(topicExchange()).with(ROUTINGKEY02);
//    }
}
